<?php

Route::group(['prefix' => 'admin', 'middleware' => 'admin.auth', 'namespace' => 'Admin'], function () {
    Route::get('/index', 'IndexController@index')->name('admin-index');

    Route::get('/login', 'Auth\LoginController@login')->name('admin-to-login');
    Route::post('/login', 'Auth\LoginController@login')->name('admin-login');
    Route::get('/logout', 'Auth\LoginController@logout')->name('admin-logout');
    Route::get('/verify', 'Auth\LoginController@verify')->name('admin-verify');

    Route::get('/user/create', 'Auth\UserController@toCreate')->name('admin-user-create')->middleware('permission:admin-user-create');
    Route::get('/user/{user}/edit', 'Auth\UserController@toEdit')->name('admin-user-edit')->middleware('permission:admin-user-edit');
    Route::post('/user/{user}/delete', 'Auth\UserController@delete')->name('admin-user-delete')->middleware('permission:admin-user-delete');
    Route::post('/user/save', 'Auth\UserController@save')->name('admin-user-save')->middleware('permission:admin-user-create|admin-user-edit');
    Route::get('/users', 'Auth\UserController@users')->name('admin-users')->middleware('permission:admin-users');

    Route::get('/role/create', 'Auth\RoleController@toCreate')->name('admin-role-create')->middleware('permission:admin-role-create');
    Route::get('/role/{role}/edit', 'Auth\RoleController@toEdit')->name('admin-role-edit')->middleware('permission:admin-role-edit');
    Route::post('/role/{role}/delete', 'Auth\RoleController@delete')->name('admin-role-delete')->middleware('permission:admin-role-delete');
    Route::post('/role/save', 'Auth\RoleController@save')->name('admin-role-save')->middleware('permission:admin-role-create|admin-role-edit');
    Route::get('/roles', 'Auth\RoleController@roles')->name('admin-roles')->middleware('permission:admin-roles');

    Route::get('/permission/create', 'Auth\PermissionController@toCreate')->name('admin-permission-create')->middleware('permission:admin-permission-create');
    Route::get('/permission/{permission}/edit', 'Auth\PermissionController@toEdit')->name('admin-permission-edit')->middleware('permission:admin-permission-edit');
    Route::post('/permission/{permission}/delete', 'Auth\PermissionController@delete')->name('admin-permission-delete')->middleware('permission:admin-permission-delete');
    Route::post('/permission/save', 'Auth\PermissionController@save')->name('admin-permission-save')->middleware('permission:admin-permission-create|admin-permission-edit');
    Route::get('/permissions', 'Auth\PermissionController@permissions')->name('admin-permissions')->middleware('permission:admin-permissions');

    Route::get('/menu/create', 'Auth\MenuController@toCreate')->name('admin-menu-create')->middleware('permission:admin-menu-create');
    Route::get('/menu/{menu}/edit', 'Auth\MenuController@toEdit')->name('admin-menu-edit')->middleware('permission:admin-menu-edit');
    Route::post('/menu/{menu}/delete', 'Auth\MenuController@delete')->name('admin-menu-delete')->middleware('permission:admin-menu-delete');
    Route::post('/menu/save', 'Auth\MenuController@save')->name('admin-menu-save')->middleware('permission:admin-menu-create|admin-menu-edit');
    Route::get('/menus', 'Auth\MenuController@menus')->name('admin-menus')->middleware('permission:admin-menus');

    //添加用户角色
    Route::post('/user/attach', 'Auth\UserController@attachRole')->name('admin-user-attach')->middleware('permission:admin-user-attach');
    Route::get('/role/select', 'Auth\RoleController@select')->name('admin-role-select')->middleware('permission:admin-user-attach');
    //添加角色的权限
    Route::post('/role/attach', 'Auth\RoleController@attachPermission')->name('admin-role-attach')->middleware('permission:admin-role-attach');
    Route::get('/permission/select', 'Auth\PermissionController@select')->name('admin-permission-select')->middleware('permission:admin-role-attach');
});